package com.itheima.clone.serializableDeppCopy;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @program: itheima-jdk8
 * @description:
 * @author: zhanghz001
 * @create: 2021-01-10 14:25
 **/
public class DeepCopy1 {
    public static void main(String[] args) {
        Person person1 = new Person("name_person_1", 111);
        Student s1 = new Student("name1", 11, person1);
        System.out.println(s1);
        
        //
        
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
             ObjectOutputStream oos = new ObjectOutputStream(baos);
        ) {
            oos.writeObject(s1);
            oos.flush();
            try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
            ) {
                
                Student s2 = (Student) ois.readObject();
                s2.getPerson().setName("aaaa");
                s2.setName("222");
                System.out.println(s2);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            
        }
        
    }
}
